<template>
	<view class="container">
		<view class="header">
			<u-icon name="arrow-left" size="32" color="#333" @click="goBack"></u-icon>
			<text class="title">患者信息</text>
		</view>
		<view class="content">
			<view class="card">
				<view class="patient-info">
					<image class="avatar" :src="patientInfo.avatar || '/static/touxiang.png'" mode="aspectFill"></image>
					<view class="info">
						<text class="name">{{patientInfo.name}}</text>
						<text class="age">{{patientInfo.age}}岁</text>
						<text class="gender">{{patientInfo.gender}}</text>
					</view>
				</view>
				<view class="basic-info">
					<view class="info-item">
						<text class="label">身份证号</text>
						<text class="value">{{patientInfo.idCard}}</text>
					</view>
					<view class="info-item">
						<text class="label">联系电话</text>
						<text class="value">{{patientInfo.phone}}</text>
					</view>
					<view class="info-item">
						<text class="label">住址</text>
						<text class="value">{{patientInfo.address}}</text>
					</view>
					<view class="info-item">
						<text class="label">紧急联系人</text>
						<text class="value">{{patientInfo.emergencyContact}}</text>
					</view>
				</view>
			</view>
			<view class="card">
				<view class="card-title">病史信息</view>
				<view class="medical-history">
					<view class="info-item">
						<text class="label">既往病史</text>
						<text class="value">{{patientInfo.medicalHistory}}</text>
					</view>
					<view class="info-item">
						<text class="label">家族病史</text>
						<text class="value">{{patientInfo.familyHistory}}</text>
					</view>
					<view class="info-item">
						<text class="label">过敏史</text>
						<text class="value">{{patientInfo.allergies}}</text>
					</view>
					<view class="info-item">
						<text class="label">当前用药</text>
						<text class="value">{{patientInfo.currentMedication}}</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				patientId: 0,
				patientInfo: {
					avatar: '/static/touxiang.png',
					name: '张三',
					age: 45,
					gender: '男',
					idCard: '310********1234',
					phone: '13800138000',
					address: '上海市浦东新区张江高科技园区',
					emergencyContact: '李四 (配偶) 13900139000',
					medicalHistory: '高血压(2010年起)，2型糖尿病(2015年起)',
					familyHistory: '父亲有高血压，母亲有2型糖尿病',
					allergies: '青霉素',
					currentMedication: '拜新同(5mg，每日一次)，格华止(500mg，每日两次)'
				},
				defaultData: {
					avatar: '/static/touxiang.png',
					name: '张三',
					age: 45,
					gender: '男',
					idCard: '310********1234',
					phone: '13800138000',
					address: '上海市浦东新区张江高科技园区',
					emergencyContact: '李四 (配偶) 13900139000',
					medicalHistory: '高血压(2010年起)，2型糖尿病(2015年起)',
					familyHistory: '父亲有高血压，母亲有2型糖尿病',
					allergies: '青霉素',
					currentMedication: '拜新同(5mg，每日一次)，格华止(500mg，每日两次)'
				}
			}
		},
		methods: {
			goBack() {
				uni.navigateBack();
			},
			async loadData() {
				try {
					// 使用患者ID加载对应的患者信息
					const id = this.patientId;
					console.log('加载患者信息，ID:', id);
					
					// 模拟API调用，实际项目中应该使用真实API
					// const res = await uni.$u.http.get(`/api/consultation/patient/${id}`);
					const res = {
						code: 200,
						data: {
							id: id,
							avatar: '/static/touxiang.png',
							name: '张三',
							age: 45,
							gender: '男',
							idCard: '310********1234',
							phone: '13800138000',
							address: '上海市浦东新区张江高科技园区',
							emergencyContact: '李四 (配偶) 13900139000',
							medicalHistory: '高血压(2010年起)，2型糖尿病(2015年起)',
							familyHistory: '父亲有高血压，母亲有2型糖尿病',
							allergies: '青霉素',
							currentMedication: '拜新同(5mg，每日一次)，格华止(500mg，每日两次)'
						}
					};
					
					if (res.code === 200) {
						this.patientInfo = {
							...this.defaultData,
							...res.data
						};
					} else {
						uni.showToast({
							title: res.msg || '获取数据失败',
							icon: 'none'
						});
						this.patientInfo = this.defaultData;
					}
				} catch (e) {
					console.error('获取患者信息失败:', e);
					uni.showToast({
						title: '获取数据失败',
						icon: 'none'
					});
					this.patientInfo = this.defaultData;
				}
			}
		},
		onLoad(options) {
			// 获取路由参数中的患者ID
			if (options && options.id) {
				this.patientId = options.id;
			}
			this.loadData();
		}
	}
</script>

<style lang="scss">
	.container {
		padding: 30rpx;
		.header {
			display: flex;
			align-items: center;
			margin-bottom: 40rpx;
			.title {
				font-size: 36rpx;
				font-weight: bold;
				color: #333;
				margin-left: 20rpx;
			}
		}
		.content {
			.card {
				background-color: #fff;
				border-radius: 16rpx;
				padding: 30rpx;
				margin-bottom: 30rpx;
				box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
				.patient-info {
					display: flex;
					align-items: center;
					margin-bottom: 30rpx;
					.avatar {
						width: 120rpx;
						height: 120rpx;
						border-radius: 60rpx;
						margin-right: 30rpx;
					}
					.info {
						.name {
							font-size: 32rpx;
							font-weight: bold;
							color: #333;
							margin-right: 20rpx;
						}
						.age, .gender {
							font-size: 28rpx;
							color: #666;
							margin-right: 10rpx;
						}
					}
				}
				.card-title {
					font-size: 32rpx;
					font-weight: bold;
					color: #333;
					margin-bottom: 30rpx;
				}
				.basic-info, .medical-history {
					.info-item {
						display: flex;
						flex-direction: column;
						margin-bottom: 20rpx;
						&:last-child {
							margin-bottom: 0;
						}
						.label {
							font-size: 28rpx;
							color: #666;
							margin-bottom: 10rpx;
						}
						.value {
							font-size: 28rpx;
							color: #333;
							line-height: 1.6;
						}
					}
				}
			}
		}
	}
</style> 